package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.entity.News;
import com.example.mapper.NewsMapper;
import com.example.qo.NewsQuery;
import com.example.service.INewsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yunan
 * @since 2023-04-13
 */
@Service
public class NewsServiceImpl extends ServiceImpl<NewsMapper, News> implements INewsService {

    @Autowired
    private NewsMapper newsMapper;

    @Override
    public Page<News> queryPage(NewsQuery qo) {
        Page<News> pageParam = new Page<>();
        pageParam.setCurrent(qo.getCurrent());
        pageParam.setSize(qo.getSize());
        QueryWrapper<News> qw = new QueryWrapper<>();
        return newsMapper.selectPage(pageParam, qw);
    }

    @Override
    public void updateViewNum(Long id, Long viewnum) {
        UpdateWrapper<News> uw = new UpdateWrapper<>();
        uw.eq("id", id);
        uw.set("viewnum", viewnum);
        newsMapper.update(null, uw);
    }
}
